import { createPinia } from 'pinia';
import { createPersistedState } from 'pinia-plugin-persistedstate';
function getURLParameters(url) {
  const paramsObj = {};
  const queryString = url.split('?')[1];
  if (queryString) { 
    const keyValuePairs = queryString.split('&');
    keyValuePairs.forEach((pair) => {
      const [key, value] = pair.split('=');
      if (key && value) {
        paramsObj[key] = decodeURIComponent(value.replace(/\+/g, ' '));
      }
    });
  }
  return paramsObj;
}
function getStorageKey(): string {
  const url = window.location.href;
  const regex = /\/(\d+)/; // 匹配数字参数的正则表达式
  const match = url.match(regex); // 使用正则表达式匹配数字参数

  if (match) {
    const numericParam = parseInt(match[1]); // 提取数字参数并将其转换为数字类型
    // alert(numericParam);
    // console.log(numericParam); // 输出数字参数的值
    // localStorage.setItem('projectId', String(numericParam));
    return `${numericParam}`;
  } 

  // console.log(arr);  
  // const name = params.get('projectId'); 

  // const { pathname, search, hash } = window.location;
  // return `${pathname}${search}${hash}`; 
}
// let keyName: string = getStorageKey();
const persistedState = createPersistedState({
  key: getStorageKey, // 自定义存储键名
});
const store = createPinia();
store.use(persistedState);
 
export { store }; 
 
export * from './modules/permission'; 
export * from './modules/user';
export * from './modules/project';
export * from './modules/Exhibit';
export * from './modules/commonData';

export default store;
